package wechat.rcv.controller

import com.shrcl.engineerprocess.domain.CorpWeChatUserDAO
import edu.fudan.mylang.pf.IObjectFactory
import java.util.ArrayList
import org.apache.log4j.Logger
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import wechat.app.UserID

@Controller
class NotificationList {
	final static Logger logger = Logger.getLogger(typeof(NotificationList).getName());
 	@Autowired IObjectFactory entities;
 	@Autowired CorpWeChatUserDAO corpWeChatUserDAO
 	
	@RequestMapping("/notificationlist")
	def String process( 
			@RequestParam(value = "code", defaultValue = "") String code,
			@RequestParam(value = "state", defaultValue = "") String state,
			Model model
	) {
		logger.info('=========>NotificationList.processs<============')
		val eng = corpWeChatUserDAO.findActiveWeChatUser(UserID::getUserId(code))?.engineer
		var hpage = 'error'
		if (eng==null){
			model.addAttribute("errormsg", "Invalid user");
		}
		else{
			val arr = new ArrayList();
//			val n1 = new WXNotification("Daily Meeting","15:45","Meeting Room A","Lynn","04-14","周五");
//			val n2 = new WXNotification("UIDL Meeting","17:01","Meeting Room A","Lynn","04-17","Monday");
//			arr.add(n1);
//			arr.add(n2);
			model.addAttribute("result",arr);			
			hpage = 'notificationlist'
		}
		hpage;
	}
}